      SUBROUTINE E01DAX(XMIN,XMAX,M,X,W,IW1,LW,IFNZWT,MNZWT,MDNZWT,
     *                  IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     A DASL routine, unmodified except for name.
C
C     **********************************************************
C
C     D A S L  -  DATA APPROXIMATION SUBROUTINE LIBRARY
C
C     SUBROUTINE CHKWX     CHECK WEIGHT AND ABSCISSA ARRAYS
C     ================
C
C     CREATED 05 03 80.  UPDATED 23 04 82.  RELEASE 00/04
C
C     AUTHORS ... GERALD T. ANTHONY, MAURICE G. COX AND
C                 PAULINE E. M. CURTIS.
C     NATIONAL PHYSICAL LABORATORY, TEDDINGTON,
C     MIDDLESEX TW11 OLW, ENGLAND
C
C     (C)  CROWN COPYRIGHT 1980-1982
C
C     **********************************************************
C
C     CHKWX.  CHECKS THAT THE X-VALUES OF DATA POINTS WITH
C     NONZERO WEIGHT ARE IN NONDECREASING ORDER AND LIE
C     IN THE CLOSED INTERVAL  XMIN  TO  XMAX.
C     THE INDEX OF THE FIRST DATA POINT WITH NONZERO
C     WEIGHT, THE NUMBER OF DATA POINTS WITH NONZERO
C     WEIGHTS AND THE NUMBER OF DISTINCT DATA POINTS WITH
C     NONZERO WEIGHTS ARE DETERMINED.
C
C     INPUT PARAMETERS
C        XMIN,
C        XMAX     LOWER AND UPPER ENDPOINTS OF INTERVAL
C        M        NUMBER OF DATA VALUES
C        X        ABSCISSA VALUES
C        W        WEIGHTS (INVERSELY PROPORTIONAL TO
C                    ESTIMATED ERRORS IN F-VALUES)
C        IW1      INDEX INCREMENT OF  W
C        LW       DIMENSION OF  W
C
C     OUTPUT PARAMETERS
C        IFNZWT   INDEX OF FIRST DATA POINT WITH NONZERO
C                    WEIGHT
C        MNZWT    NUMBER OF DATA POINTS WITH NONZERO WEIGHT
C        MDNZWT   NUMBER OF DATA POINTS WITH DISTINCT
C                    ABSCISSA VALUES AND NONZERO WEIGHT
C                    (ONLY IF  IFAIL = 0)
C
C     FAILURE INDICATOR PARAMETER
C        IFAIL    FAILURE INDICATOR
C                    0 - SUCCESSFUL TERMINATION
C                    1 - AN X-VALUE WITH NONZERO WEIGHT
C                        LIES OUTSIDE THE CLOSED INTERVAL
C                        XMIN  TO  XMAX
C                    2 - THE X-VALUES WITH NONZERO WEIGHTS
C                        ARE NOT IN NONDECREASING ORDER
C
C     ----------------------------------------------------------
C
C     .. Scalar Arguments ..
      DOUBLE PRECISION  XMAX, XMIN
      INTEGER           IFAIL, IFNZWT, IW1, LW, M, MDNZWT, MNZWT
C     .. Array Arguments ..
      DOUBLE PRECISION  W(LW), X(M)
C     .. Local Scalars ..
      DOUBLE PRECISION  XPREV, ZERO
      INTEGER           IDNZWT, IERROR, INZWT, IW, R, RSTART
C     .. Data statements ..
C
      DATA              ZERO/0.0D+0/
C     .. Executable Statements ..
C
      IERROR = 0
      INZWT = 0
      IDNZWT = 0
C
C     DETERMINE THE INDEX  IFNZWT  OF THE FIRST DATA POINT
C     WITH NONZERO WEIGHT
C
      IW = 1 - IW1
      DO 20 R = 1, M
         IW = IW + IW1
         IF (W(IW).NE.ZERO) GO TO 40
   20 CONTINUE
      IFNZWT = M + 1
      GO TO 100
   40 RSTART = R
      IFNZWT = RSTART
      INZWT = 1
      IDNZWT = 1
C
C     CHECK WHETHER EACH DATA POINT WITH NONZERO WEIGHT
C     LIES IN THE CLOSED INTERVAL  XMIN  TO  XMAX
C
      IERROR = 1
      IW = 1 + (RSTART-2)*IW1
      DO 60 R = RSTART, M
         IW = IW + IW1
         IF ((X(R).LT.XMIN .OR. X(R).GT.XMAX) .AND. W(IW).NE.ZERO)
     *       GO TO 120
   60 CONTINUE
      IERROR = 0
      IF (RSTART.EQ.M) GO TO 100
C
C     CHECK WHETHER THE REMAINING DATA POINTS WITH NONZERO
C     WEIGHTS HAVE X-VALUES IN NONDECREASING ORDER, AND
C     DETERMINE THE VALUES OF  MNZWT  AND  MDNZWT
C
      IERROR = 0
      XPREV = X(RSTART)
      RSTART = RSTART + 1
      IW = 1 + (RSTART-2)*IW1
      DO 80 R = RSTART, M
         IW = IW + IW1
         IF (W(IW).EQ.ZERO) GO TO 80
         IF (X(R).LT.XPREV) IERROR = 2
         INZWT = INZWT + 1
         IF (X(R).GT.XPREV) IDNZWT = IDNZWT + 1
         XPREV = X(R)
   80 CONTINUE
  100 MNZWT = INZWT
      IF (IERROR.EQ.0) MDNZWT = IDNZWT
  120 IFAIL = IERROR
      RETURN
C
C     END E01DAX
C
      END
